﻿<!DOCTYPE html>
<html>
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,user-scalable=no" />
    <link href="/Plugins/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet" />
    <link href="/Plugins/layui/css/layui.css" rel="stylesheet" />
    <link href="/Content/lgm/css/login.css" rel="stylesheet" />
    <link href="/Plugins/layer/theme/default/layer.css" rel="stylesheet" />
    <script src="/Plugins/common/jquery.js"></script>
    <script src="/Plugins/layer/layer.js"></script>
    <script src="/Plugins/common/vue.3.2.js"></script>
    <script src="/Plugins/common/lg.base.js"></script>
    <title></title>
</head>
<body>
    <div class="layui-card" id="ChangePassword">
        <div class="layui-card-body">
            <div class="layui-form-item">
                <form class="layui-form layui-form-pane lg-form" action="" id="fm_EidtPwd" lay-filter="fm_EditPwd">
                    <div class="layui-form-item">
                        <label class="layui-form-label">原始密码</label>
                        <div class="layui-input-block">
                            <input type="password" name="oldKey" class="layui-input lg-form-reg" data-reg="required" autocomplete="off" v-model="form.oldKey" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">更新密码</label>
                        <div class="layui-input-block">
                            <input type="password" name="newKey" class="layui-input lg-form-reg" data-reg="required|password" autocomplete="off" v-model="form.newKey" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">确认密码</label>
                        <div class="layui-input-block">
                            <input type="password" name="cfmKey" class="layui-input lg-form-reg" data-reg="required|password" autocomplete="off" v-model="form.cfmKey" />
                        </div>
                    </div>
                    <div class="layui-form-item text-center">
                        <button type="button" v-on:click="Change()" class="layui-btn layui-btn-warm" style="width:100%;">立即提交</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script>
        Vue.createApp({
            data() {
                return {
                    form: {
                        oldKey: "",
                        newKey: "",
                        cfmKey: ""
                    }
                }
            },
            methods: {
                Change: function() {
                    var res= lg.form.validate({ errClass: "reg-error", target:".lg-form-reg"})
                    console.log(res)
                    if (this.form.newKey != this.form.cfmKey) {
                        layer.msg("两次输入的密码不一致!", { icon: 2 })
                        return false
                    }
                    if (this.form.newKey == this.form.oldKey) {
                        layer.msg("新旧密码不可一致！", { icon: 2 })
                        return false
                    }
                    lg.request({
                        url: "/base/ChangePassword",
                        method: "post",
                        data: this.form,
                        success: res => {
                            if (res.code == 0) {
                                layer.msg("密码修改成功，请重新登陆", { icon: 1, time: 1000 }, function() {
                                    lg.request({
                                        url: "/base/logOut",
                                        success: res => {
                                            if (res.code == 0) {
                                                top.location.href = "/Lgm";
                                            } else {
                                                layer.msg(res.msg, { icon: 2 })
                                            }
                                        }
                                    })
                                })
                            } else {
                                layer.msg(res.msg, { icon: 2 })
                            }
                        }
                    })
                },
            }
        }).mount("#ChangePassword")
    </script>
</body>
</html>